home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / xvisrc.zip / MSDOS_A.ASM < prev    next >
Assembly Source File  |  1992-07-28  |  6KB  |  294 lines

  1. ; Copyright (c) 1990,1991,1992 Chris and John Downey
  2. _TEXT    segment word public 'CODE'
  3.     db    "@(#)msdos_a.asm    2.1 (Chris & John Downey) 7/29/92"
  4.     db    0
  5. _TEXT    ends
  6.  
  7. ;***
  8. ;
  9. ; program name:
  10. ;    xvi
  11. ; function:
  12. ;    PD version of UNIX "vi" editor, with extensions.
  13. ; module name:
  14. ;    msdos_a.asm
  15. ; module function:
  16. ;    Assembly language part of system interface module for MS-DOS.
  17. ;
  18. ;    This code has been assembled with Microsoft's Macro Assembler
  19. ;    (MASM) version 5.1, & is compatible with code generated by
  20. ;    MS-DOS C compilers using the normal large memory model calling
  21. ;    conventions. This includes the Microsoft & Zortech compilers.
  22. ;
  23. ;    The ignore_signals() routine installs handlers for keyboard &
  24. ;    critical error interrupts. Critical error interrupts are
  25. ;    generated for events like trying to access a diskette when
  26. ;    there isn't one in the drive, or it isn't formatted, etc. The
  27. ;    system's default interrupt handler just displays a message
  28. ;    followed by "Abort, Retry, Fail?", which destroys our editing
  29. ;    screen, & if the user presses 'a', the current process gets
  30. ;    killed without further warning. We don't want this to happen
  31. ;    to xvi, so we install our own handler, which just pretends the
  32. ;    user chose the "Ignore" option (or "Fail" on MS-DOS 3.0 or
  33. ;    later) by returning 0 (for "Ignore") or 3 (for "Fail") in the
  34. ;    AL register.
  35. ;
  36. ;    Note that most MS-DOS system calls, if issued from within a
  37. ;    critical error handler, will cause the system to crash
  38. ;    (because the system itself isn't re-entrant). 
  39. ; history:
  40. ;
  41. ;    STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  42. ;    Originally by Tim Thompson (twitch!tjt)
  43. ;    Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  44. ;    Heavily modified by Chris & John Downey
  45. ;***
  46.  
  47. include 8086mm.inc
  48.  
  49.         public    _msdsignal
  50.         public    _catch_signals
  51.         public    _getchnw
  52.         public    _dup
  53.         public    _dup2
  54.  
  55. _TEXT        segment word public 'CODE'
  56.         even
  57. ;
  58. ; Address of interrupt flag.
  59. ;
  60. iflagaddr    label    dword
  61. iflagoff    dw    ?
  62. iflagseg    dw    ?
  63.  
  64. ;
  65. ; Major MS-DOS version number.
  66. ;
  67. sysversion    db    ?
  68.  
  69.         assume    nothing
  70.         assume    cs:_TEXT
  71. _msdsignal:
  72.         ;
  73.         ; void msdsignal(unsigned char *flagp);
  74.         ;
  75.         ; Install interrupt handlers.
  76.         ;
  77.         ; This routine is called by ignore_signals() with the
  78.         ; address of the interrupt flag in flagp.
  79.         ;
  80.         mov    bx, sp
  81.         push    ds
  82.         ;
  83.         ; Store address of interrupt flag.
  84.         ;
  85.     if DPTRSIZE eq 4
  86.         lds    ax, ss:[bx + CPTRSIZE]
  87.     else
  88.         mov    ax, [bx + CPTRSIZE]
  89.     endif
  90.         mov    dx, ds
  91.         mov    cx, cs
  92.         mov    ds, cx
  93.         assume    ds: _TEXT
  94.         mov    iflagoff, ax
  95.         mov    iflagseg, dx
  96.         ;
  97.         ; Get MS-DOS major version number.
  98.         ;
  99.         mov    ah, 30h
  100.         int    21h
  101.         mov    sysversion, al
  102.         ;
  103.         ; Install keyboard interrupt handler.
  104.         ;
  105.         mov    dx, offset kbd
  106.         mov    ax, 2523h    ; Keyboard interrupt is 23h.
  107.         int    21h
  108.         ;
  109.         ; Install critical error handler.
  110.         ;
  111.         mov    dx, offset criterr
  112.         mov    ax, 2524h    ; Critical error interrupt is 24h.
  113.         int    21h
  114.         pop    ds
  115.         assume    ds: nothing
  116.         C_ret
  117.  
  118. _catch_signals:
  119.         ;
  120.         ; void catch_signals(void);
  121.         ;
  122.         ; Set console break flag so that we can be interrupted
  123.         ; even when we're not waiting for console input.
  124.         ;
  125.         mov    ax, 3301h
  126.         mov    dl, 1
  127.         int    21h
  128.         C_ret
  129.  
  130.         assume    nothing
  131.         assume    cs: _TEXT
  132.  
  133. criterr:            ; Entry point for critical error interrupts.
  134.         pushf
  135.         sti
  136.         clear    al
  137.         cmp    sysversion, 3
  138.         jb    ignore
  139.         mov    al, 3
  140. ignore:
  141.         popf
  142.         iret
  143. kbd:                ; Entry point for keyboard interrupts.
  144.         push    ds
  145.         push    bx
  146.         ;
  147.         ; Increment interrupt flag.
  148.         ;
  149.         lds    bx, iflagaddr
  150.         mov    byte ptr [bx], 1
  151.         pop    bx
  152.         pop    ds
  153.         iret
  154.  
  155.         assume    nothing
  156.         assume    cs: _TEXT
  157. _getchnw:
  158.         ;
  159.         ; int getchnw();
  160.         ;
  161.         ; Return a character from standard input if one is
  162.         ; immediately available, otherwise -1.
  163.         ;
  164.         mov    dl, 0ffh
  165.         mov    ah, 6
  166.         int    21h
  167.         jz    notavail
  168.         clear    ah
  169.         C_ret
  170. notavail:
  171.         mov    ax, -1
  172.         C_ret
  173.  
  174. _dup:
  175.         ;
  176.         ; int dup(int fd);
  177.         ;
  178.         ; Duplicate file descriptor.
  179.         ;
  180.         push    bp
  181.         mov    bp, sp
  182.         mov    bx, [bp + CPTRSIZE + 2]
  183.         mov    ah, 45h
  184.         int    21h
  185.         ;
  186.         ; Return -1 if CF is set, otherwise new descriptor.
  187.         ;
  188.         sbb    bx, bx
  189.         or    ax, bx    ; New descriptor is in AX.
  190.         pop    bp
  191.         C_ret
  192.  
  193. _dup2:
  194.         ;
  195.         ; int dup2(int fd1, int fd2);
  196.         ;
  197.         ; Duplicate file descriptor with specified new value.
  198.         ;
  199.         push    bp
  200.         mov    bp, sp
  201.         mov    bx, [bp + CPTRSIZE + 2] ; Existing descriptor.
  202.         mov    cx, [bp + CPTRSIZE + 4] ; New descriptor.
  203.         mov    ah, 46h
  204.         int    21h
  205.         ;
  206.         ; Return -1 if CF is set, otherwise 0.
  207.         ;
  208.         sbb    ax, ax
  209.         pop    bp
  210.         C_ret
  211.  
  212. ;
  213. ; The following code is untested because neither of us has access to
  214. ; an MS-DOS development system at the moment.
  215. ;
  216. ;            assume    nothing
  217. ;            assume    cs: _TEXT
  218. ;
  219. ;    setdta        proc    near
  220. ;            ;
  221. ;            ; Set DOS's Disk Transfer Address to the address
  222. ;            ; pointed to by ss:bx. This is either a near or far
  223. ;            ; pointer, depending on what C memory model we're
  224. ;            ; using.
  225. ;            ;
  226. ;            mov    ah, 1ah
  227. ;        if DPTRSIZE eq 2        ; Small or medium memory model.
  228. ;            mov    dx, [bx]
  229. ;            int    21h
  230. ;        else
  231. ;            push    ds
  232. ;            lds    dx, ss:[bx]
  233. ;            int    21h
  234. ;            pop    ds
  235. ;        endif
  236. ;            ret
  237. ;    setdta        endp
  238. ;
  239. ;    _statfirst:
  240. ;            ;
  241. ;            ; int statfirst(char * name, struct dstat * info,
  242. ;            ;        int attribute);
  243. ;            ;
  244. ;            ; Return information on a named file or the first file
  245. ;            ; matching a given specification.
  246. ;            ;
  247. ;            ; This is like stat(2) on Unix except that it does
  248. ;            ; pattern matching with '*' & '?' (in the base name
  249. ;            ; only, not in any directory names). If there are
  250. ;            ; multiple matches, statfirst() only returns
  251. ;            ; information on the first one & statnext() can be
  252. ;            ; called successively for subsequent ones.
  253. ;            ;
  254. ;            ; The base name is returned, in capital letters, in
  255. ;            ; the dstat structure, together with some other
  256. ;            ; information.
  257. ;            ;
  258. ;            mov    bx, sp
  259. ;            add    bx, CPTRSIZE + DPTRSIZE
  260. ;            ;
  261. ;            ; ss:bx now points to our struct dstat pointer.
  262. ;            ;
  263. ;            call    setdta
  264. ;        if DPTRSIZE eq 2
  265. ;            mov    dx, [bx - DPTRSIZE]
  266. ;            mov    cx, [bx + DPTRSIZE]
  267. ;        else
  268. ;            lds    dx, ss:[bx - DPTRSIZE]
  269. ;            mov    cx, ss:[bx + DPTRSIZE]
  270. ;        endif
  271. ;            mov    ah, 4eh
  272. ;            int    21h
  273. ;            sbb    ax, ax
  274. ;            C_ret
  275. ;
  276. ;    _statnext:
  277. ;            ;
  278. ;            ; int statnext(struct dstat *info);
  279. ;            ;
  280. ;            ; See above.
  281. ;            ;
  282. ;            mov    bx, sp
  283. ;            add    bx, CPTRSIZE
  284. ;            ;
  285. ;            ; ss:bx now points to our struct dstat pointer.
  286. ;            ;
  287. ;            call    setdta
  288. ;            mov    ah, 4fh
  289. ;            int    21h
  290. ;            sbb    ax, ax
  291. ;            C_ret
  292. _TEXT        ends
  293.         end
  294.